//
//  NSError+Extension.swift
//  8btc
//
//  Created by Felix Yuan on 2020/4/16.
//  Copyright © 2020 Hangzhou Shichuo Information Technology Co, Ltd. All rights reserved.
//

import Foundation

public extension NSError {
    class var emptyErrorDomain: String { return Bundle.main.bundleIdentifier! }
    class var emptyErrorCode: Int { return 1024 }
    class var empty: NSError {
        return NSError(domain: emptyErrorDomain, code: emptyErrorCode, userInfo: nil)
    }
    
    class func make(message: String, code: Int = 9999) -> NSError {
        return NSError(
            domain:  Bundle.main.bundleIdentifier! ,
            code: code,
            userInfo: [NSLocalizedDescriptionKey: message, NSLocalizedFailureReasonErrorKey: message]
        )
    }
    
    var userInterfaceInfo: String {
        if let userInfoError = userInfo["message"] as? String {
            return userInfoError
        }else if let userInfoError = userInfo["desc"] as? String {
            return userInfoError
        }
        return localizedDescription
    }
}

public func NSErrorFrom(message: String, code: Int = 9999) -> NSError {
    return NSError.make(message: message, code: code)
}
